package ru.ognick.coachsystem.common.base;


import java.util.ArrayList;

import ru.ognick.coachsystem.common.Exercise;
import ru.ognick.coachsystem.common.Training;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

public abstract class BaseExerciseAdapter<T extends BaseExerciseView> extends ArrayAdapter<T> {
    protected final String TAG = getClass().getSimpleName();	
    protected ArrayList<T> exercises;
	
	public void loadData(Training training) {
		exercises.clear();
		for (Exercise exercise : training.getExercises()) 
			add(exercise);
        notifyDataSetChanged();
	}
	
	public BaseExerciseAdapter(Context context, 
							   int textViewResourceId, 
							   ArrayList<T> exercises) {
		super(context, textViewResourceId, exercises);
		this.exercises = exercises;
		setNotifyOnChange(true);
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
		return exercises.get(position).getView();
	}
	
	public T getItem(int position) {
		return exercises.get(position);
	}
	
	public void remove(BaseExerciseView BaseExerciseView){
			exercises.remove(BaseExerciseView);
	        notifyDataSetChanged();
	}
	
	
	public abstract BaseExerciseView add(Exercise exercise);
}
